package com.java.simple.study.juc.p3.deadlock;

import com.java.simple.study.tool.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhoujl
 * @date 2022/5/10 20:49
 * @desc
 */
@Slf4j(topic = "c.TestDeadLock")
public class TestDeadLock {

    private static final Object A = new Object();
    private static final Object B = new Object();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                log.debug("lock A");
                Sleeper.sleep(1);
                synchronized (B) {
                    log.debug("lock B");
                    log.debug("操作。。。");
                }
            }
        }, "t1");

        Thread t2 = new Thread(() -> {
            synchronized (B) {
                log.debug("lock B");
                Sleeper.sleep(0.5);
                synchronized (A) {
                    log.debug("lock A");
                    log.debug("操作。。。");
                }
            }
        }, "t2");

        t1.start();
        t2.start();

        /*解决方法  两个线程均顺序加锁*/

    }


}
